import 'package:black_movice/config/configs.dart';
import 'package:black_movice/models/UserModel.dart';
import 'package:black_movice/store/store.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class UserInfo extends StatefulWidget {
  const UserInfo({super.key});

  @override
  State<UserInfo> createState() => _UserInfoState();
}

// 用户信息，包括登录，推广小卡片
class _UserInfoState extends State<UserInfo> {
  final Store store = Get.find<Store>(); //获取store状态管理器控制器
  @override
  Widget build(BuildContext context) {
    return Obx(() {
      UserModel userModel = store.userModel.value;
      return Column(
        children: [
          Padding(
            padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 10.w),
            child: Row(
              children: [
                // 头像组件
                CircleAvatar(
                  radius: 40.h,
                  backgroundColor: Colors.grey.withValues(alpha: .5),
                  backgroundImage: userModel.userAvatar.isEmpty
                      ? null
                      : ExtendedNetworkImageProvider(userModel.userAvatar),
                  child: userModel.userAvatar.isEmpty
                      ? const Icon(
                          Icons.person,
                          color: Colors.white,
                          size: 50,
                        )
                      : null,
                ),
                // 名称，id
                Expanded(
                    child: Padding(
                  padding: EdgeInsets.only(left: 10.sp),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(userModel.userName,
                          style: TextStyle(fontSize: 24.sp)),
                      Text("${userModel.id ?? '开启小黑视频之旅'}",
                          style: TextStyle(fontSize: Configs.textSize_12))
                    ],
                  ),
                )),
              ],
            ),
          ),
          // 推广小卡片
          Expanded(
            child: Padding(
              padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 10.w),
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10.sp),
                ),
                child: Padding(
                  padding: EdgeInsets.all(10.sp),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "免广告特权",
                            style: TextStyle(
                                fontSize: Configs.lgTitleSize_16,
                                fontWeight: FontWeight.w500),
                          ),
                          Text("暂未享受免广告特权",
                              style: TextStyle(
                                  fontSize: Configs.textSize_12,
                                  color: Colors.grey.withValues(alpha: .5))),
                        ],
                      ),
                      SizedBox(
                        height: 10.h,
                      ),
                      Expanded(
                        child: Card(
                          shadowColor: Colors.deepOrangeAccent,
                          elevation: 8.sp,
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(10.sp)),
                          child: Container(
                            padding: EdgeInsets.symmetric(
                                vertical: 10.h, horizontal: 5.w),
                            decoration: BoxDecoration(
                              // gradient: LinearGradient(colors: [colors])\
                              color: Colors.deepOrangeAccent,
                              borderRadius: BorderRadius.circular(10.sp),
                            ),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  "已经推广 ${userModel.popularizeCount} 人",
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontSize: Configs.lgTitleSize_16),
                                ),
                                Column(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Container(
                                      padding: EdgeInsets.symmetric(
                                          horizontal: 15.w, vertical: 5.h),
                                      decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(10.sp),
                                        color: Colors.white,
                                      ),
                                      child: Text(
                                        "分享推广",
                                        style: TextStyle(
                                            fontWeight: FontWeight.w500,
                                            color: Colors.deepOrangeAccent),
                                      ),
                                    ),
                                    Text(
                                      "分享可得终身免广告特权>",
                                      style: TextStyle(
                                          fontSize: Configs.tipSize_10,
                                          color: Colors.white),
                                    )
                                  ],
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      );
    });
  }
}
